package com.hibase.quartz.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import com.hibase.quartz.entity.MdsJobLog;
import com.hibase.quartz.entity.vo.*;
import com.hibase.quartz.service.MdsJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyunlei
 * @since 2020-11-18
 */
@RestController
@RequestMapping("/mds-job-log")
@Api(tags = "定时任务日志")
public class MdsJobLogController {

    @Autowired
    private MdsJobLogService mdsJobLogService;

    @ApiOperation(value = "查询列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectMdsJobLogList")
    public ResponseModel<MdsJobLogListVO> selectMdsJobLogList(@RequestBody MdsJobLogSearchVO searchVO) {

        PageInfo result = mdsJobLogService.selectMdsJobLogList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsJobLogListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertMdsJobLog")
    public ResponseModel<String> insertMdsJobLog(@RequestBody MdsJobLogInsertVO insertVO) {

        MdsJobLog entity = EntityUtil.transform(insertVO, MdsJobLog.class);

        mdsJobLogService.saveMdsJobLog(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateMdsJobLog")
    public ResponseModel<String> updateMdsJobLog(@RequestBody MdsJobLogUpdateVO updateVO) {

        MdsJobLog entity = EntityUtil.transform(updateVO, MdsJobLog.class);

        mdsJobLogService.saveMdsJobLog(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewMdsJobLogDetails")
    public ResponseModel<MdsJobLogViewVO> viewMdsJobLogDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsJobLogService.viewMdsJobLog(operationidEntity.getId()), MdsJobLogViewVO.class));
    }

    @ApiOperation(value = "删除记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteMdsJobLog")
    public ResponseModel<String> deleteMdsJobLog(@RequestBody OperationIdEntity delete) {

        mdsJobLogService.deleteMdsJobLog(delete.getId());

        return ResponseModel.successMsg();
    }
}
